package main

import (
	ServiceNetIO2 "IMServices/NetIO/ServiceNetIO"
	"IMServices/StatusService/ServerManagerCenter"
	"IMServices/StatusService/StatusCache"
	"IMServices/StatusService/StatusOrder"
	"net/http"
	_ "net/http/pprof"
)

func handleFunc(msg chan ServiceNetIO2.RequestBuffer, finish chan bool) {
	for {
		select {
		case data := <-msg:
			//启动业务函数go程
			go StatusOrder.OrderIdFunction[data.Request.OrderId](data)
		case <-finish:
			return
		}
	}

}

var index int64

func sendTest() {
	index = index + 1
	// 测试发送 gRPC 请求
	request := ServiceNetIO2.RequestBuffer{
		TargetServer: "LoginServer",
		Request: ServiceNetIO2.MessageRequest{
			Header:     []byte{},
			ServerName: "StatusServer",
			OrderId:    index,
			EncodeType: "",
			Body:       []byte{},
		},
	}
	ServiceNetIO2.AddNewMessage(request)
}

func main() {
	go func() {
		http.ListenAndServe("localhost:6060", nil)
	}()
	addr := string("localhost:12222")
	StatusCache.Init()
	StatusOrder.Init()
	//开始监听，并且打开go程函数
	go ServerManagerCenter.Server.Listen.StartServiceNet(addr, handleFunc, 1000)

	go ServerManagerCenter.Server.Connect("LoginServer", []string{"localhost:11111"})
	//go server.MessageServer.Connect([]string{"localhost:13333"})

	//var i int
	//for i = 0; i < 20; i++ {
	//	go func() {
	//		for {
	//			//time.Sleep(time.Millisecond * 50)
	//			//sendTest()
	//		}
	//	}()
	//}
	select {}
}
